<template>
  <div class="storage-location-list-container">
    <!-- 操作按钮区域 -->
    <div class="table-operator" v-if="mainId">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button @click="handlePrint" type="primary">打印</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>

      </a-table>
    </div>

    <storageLocation-modal
      ref="modalForm"
      @ok="modalFormOk"
      :mainId="mainId"
      :main-code="mainCode"
    ></storageLocation-modal>
  </div>
</template>

<script>

import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import StorageLocationModal from './modules/StorageLocationModal.vue'

export default {
  name: "StorageLocationList",
  mixins: [JeecgListMixin],
  components: { StorageLocationModal },
  props: {
    mainId: {
      type: String,
      default: '',
      required: false
    },
    mainCode: {
      type: String,
      default: '',
      required: false
    }
  },
  watch: {
    mainId: {
      immediate: true,
      handler(val) {
        if (!this.mainId) {
          this.clearList()
        } else {
          this.queryParam['warehouseId'] = val
          this.loadData(1)
        }
      }
    },
    mainCode: {
      immediate: true,
      handler(val) {
        if (!this.mainCode) {
          this.clearList()
        } else {
          this.queryParam['warehouseCode'] = val
          this.loadData(1)
        }
      }
    }
  },
  data() {
    return {
      description: '仓库信息管理页面',
      disableMixinCreated: true,
      // 表头
      columns: [
        {
          title: '储位编码',
          align: 'center',
          dataIndex: 'locationCode'
        },
        {
          title: '储位名称',
          align: 'center',
          dataIndex: 'locationName'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/wms/basic/warehouse/listStorageLocationByMainId',
        delete: '/wms/basic/warehouse/deleteStorageLocation',
        deleteBatch: '/wms/basic/warehouse/deleteBatchStorageLocation',
        exportXlsUrl: '/wms/basic/warehouse/exportStorageLocation',
        importUrl: '/wms/basic/warehouse/importStorageLocation'
      },
      dictOptions: {
        warehouseType: [],
        sysOrgCode: [],
        inboundNotice: [],
        outboundNotice: []
      }
    }
  },
  created() {
  },
  computed: {
    importExcelUrl() {
      return `${window._CONFIG['domianURL']}/${this.url.importUrl}/${this.mainId}`
    }
  },
  methods: {
    handlePrint () {
      const rows = this.selectionRows
      if (rows.length === 0) {
        this.$message.warn('请选择储位！')
        return
      }
      const ids = rows.map((item) => item.id).join('\',\'')
      window.open(`${window._CONFIG['domianURL']}/jmreport/view/1011133522876456960?id=${ids}`, '_blank')
    },
    clearList() {
      this.dataSource = []
      this.selectedRowKeys = []
      this.ipagination.current = 1
    }

  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
